<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>骑手中心 - 外卖平台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: #f5f5f5;
            color: #333;
        }
        
        .header {
            background: white;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            padding: 20px 0;
            margin-bottom: 30px;
        }
        
        .header-content {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .header h1 {
            color: #ff6b6b;
            font-size: 28px;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
        }
        
        .btn-primary {
            background: #ff6b6b;
            color: white;
        }
        
        .btn-primary:hover {
            background: #ee5a24;
            transform: translateY(-2px);
        }
        
        .btn-secondary {
            background: #6c757d;
            color: white;
        }
        
        .btn-secondary:hover {
            background: #5a6268;
        }
        
        .btn-success {
            background: #28a745;
            color: white;
        }
        
        .btn-success:hover {
            background: #218838;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        .tabs {
            display: flex;
            background: white;
            border-radius: 12px;
            padding: 4px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .tab {
            flex: 1;
            padding: 15px;
            border: none;
            background: transparent;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            color: #666;
            border-radius: 8px;
            transition: all 0.3s ease;
        }
        
        .tab.active {
            background: #ff6b6b;
            color: white;
            box-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
        }
        
        .tab-content {
            display: none;
        }
        
        .tab-content.active {
            display: block;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .stat-card {
            background: white;
            border-radius: 12px;
            padding: 25px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            text-align: center;
            transition: all 0.3s ease;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 20px rgba(0,0,0,0.15);
        }
        
        .stat-icon {
            font-size: 2.5rem;
            margin-bottom: 15px;
        }
        
        .stat-number {
            font-size: 2rem;
            font-weight: bold;
            color: #ff6b6b;
            margin-bottom: 5px;
        }
        
        .stat-label {
            color: #666;
            font-size: 0.9rem;
        }
        
        .orders-list {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .order-card {
            border: 1px solid #e9ecef;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 15px;
            transition: all 0.3s ease;
        }
        
        .order-card:hover {
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .order-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .order-id {
            font-weight: bold;
            color: #333;
        }
        
        .order-status {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
        }
        
        .status-available {
            background: #d4edda;
            color: #155724;
        }
        
        .status-accepted {
            background: #d1ecf1;
            color: #0c5460;
        }
        
        .status-delivering {
            background: #cce5ff;
            color: #004085;
        }
        
        .status-completed {
            background: #e2e3e5;
            color: #383d41;
        }
        
        .order-content {
            margin-bottom: 15px;
        }
        
        .order-content p {
            margin-bottom: 5px;
            color: #666;
        }
        
        .order-actions {
            display: flex;
            gap: 10px;
        }
        
        .map-container {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        
        .map-placeholder {
            height: 400px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
            text-align: center;
        }
        
        .back-btn {
            position: fixed;
            top: 20px;
            left: 20px;
            background: rgba(255, 107, 107, 0.8);
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            cursor: pointer;
            color: white;
            font-size: 20px;
            transition: all 0.3s ease;
            z-index: 1000;
        }
        
        .back-btn:hover {
            background: #ff6b6b;
            transform: scale(1.1);
        }
        
        .hidden {
            display: none;
        }
        
        .message {
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 20px;
            font-weight: 500;
            text-align: center;
        }
        
        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <button class="back-btn" onclick="goBack()">←</button>
    
    <div class="header">
        <div class="header-content">
            <h1>🏍️ 骑手中心</h1>
            <div class="user-info">
                <span id="riderName">骑手姓名</span>
                <button class="btn btn-secondary" onclick="logout()">退出登录</button>
            </div>
        </div>
    </div>
    
    <div class="container">
        <div id="message"></div>
        
        <div class="tabs">
            <button class="tab active" onclick="showTab('dashboard')">📊 工作概览</button>
            <button class="tab" onclick="showTab('orders')">📋 订单管理</button>
            <button class="tab" onclick="showTab('map')">🗺️ 地图导航</button>
            <button class="tab" onclick="showTab('earnings')">💰 收益分析</button>
            <button class="tab" onclick="showTab('profile')">👤 个人资料</button>
        </div>
        
        <!-- 工作概览 -->
        <div id="dashboard" class="tab-content active">
            <div class="stats-grid">
                <div class="stat-card">
                    <div class="stat-icon">📦</div>
                    <div class="stat-number" id="todayOrders">0</div>
                    <div class="stat-label">今日配送</div>
                </div>
                <div class="stat-card">
                    <div class="stat-icon">💰</div>
                    <div class="stat-number" id="todayEarnings">¥0</div>
                    <div class="stat-label">今日收入</div>
                </div>
                <div class="stat-card">
                    <div class="stat-icon">⭐</div>
                    <div class="stat-number" id="avgRating">0.0</div>
                    <div class="stat-label">平均评分</div>
                </div>
                <div class="stat-card">
                    <div class="stat-icon">⏱️</div>
                    <div class="stat-number" id="avgTime">0分钟</div>
                    <div class="stat-label">平均用时</div>
                </div>
            </div>
        </div>
        
        <!-- 订单管理 -->
        <div id="orders" class="tab-content">
            <h2>订单管理</h2>
            <div class="orders-list" id="ordersList">
                <!-- 订单将通过JavaScript动态加载 -->
            </div>
        </div>
        
        <!-- 地图导航 -->
        <div id="map" class="tab-content">
            <h2>地图导航</h2>
            <div class="map-container">
                <div class="map-placeholder">
                    <div>
                        <h3>🗺️ 配送地图</h3>
                        <p>当前位置：北京市朝阳区</p>
                        <p>待配送订单：<span id="pendingOrders">0</span>个</p>
                        <p>预计总用时：<span id="estimatedTime">0</span>分钟</p>
                        <div style="margin-top: 20px;">
                            <button class="btn btn-primary" onclick="refreshMap()">刷新地图</button>
                            <button class="btn btn-success" onclick="showRoute()">显示路线</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 收益分析 -->
        <div id="earnings" class="tab-content">
            <h2>收益分析</h2>
            <div class="earnings-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px;">
                <div class="earnings-card" style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                    <h3>💰 今日收益</h3>
                    <div style="text-align: center; margin: 20px 0;">
                        <div style="font-size: 2.5rem; color: #ff6b6b; font-weight: bold;" id="todayEarnings">¥0</div>
                        <p style="color: #666; margin: 10px 0;">今日配送费收入</p>
                    </div>
                    <div style="display: flex; justify-content: space-between;">
                        <div>
                            <p style="color: #666; font-size: 14px;">完成订单</p>
                            <p style="color: #333; font-weight: bold;" id="todayOrders">0单</p>
                        </div>
                        <div>
                            <p style="color: #666; font-size: 14px;">平均单价</p>
                            <p style="color: #333; font-weight: bold;" id="avgPrice">¥0</p>
                        </div>
                    </div>
                </div>
                
                <div class="earnings-card" style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                    <h3>📊 本周收益</h3>
                    <div id="weeklyChart" style="height: 200px; background: linear-gradient(135deg, #28a745 0%, #20c997 100%); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; font-size: 18px;">
                        周收益趋势图
                    </div>
                    <div style="margin-top: 15px;">
                        <p>本周总收入: <span style="color: #28a745; font-weight: bold;" id="weeklyTotal">¥0</span></p>
                        <p>环比增长: <span style="color: #ff6b6b; font-weight: bold;" id="weeklyGrowth">+0%</span></p>
                    </div>
                </div>
                
                <div class="earnings-card" style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                    <h3>🏆 排行榜</h3>
                    <div id="rankingList">
                        <!-- 排行榜列表 -->
                    </div>
                </div>
                
                <div class="earnings-card" style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                    <h3>💳 提现管理</h3>
                    <div style="margin-bottom: 20px;">
                        <p style="color: #666; margin-bottom: 10px;">可提现金额</p>
                        <div style="font-size: 1.5rem; color: #ff6b6b; font-weight: bold;" id="withdrawableAmount">¥0</div>
                    </div>
                    <div style="margin-bottom: 20px;">
                        <label style="display: block; margin-bottom: 5px; color: #666;">提现金额</label>
                        <input type="number" id="withdrawAmount" placeholder="请输入提现金额" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 10px;">
                    </div>
                    <button class="btn btn-primary" onclick="withdraw()" style="width: 100%;">申请提现</button>
                </div>
            </div>
        </div>
        
        <!-- 个人资料 -->
        <div id="profile" class="tab-content">
            <h2>个人资料</h2>
            <div style="background: white; border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                <div class="profile-section" style="margin-bottom: 30px;">
                    <h3>基本信息</h3>
                    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px;">
                        <div>
                            <label>姓名</label>
                            <input type="text" id="riderName" value="" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                        </div>
                        <div>
                            <label>手机号</label>
                            <input type="text" id="riderPhone" value="" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                        </div>
                        <div>
                            <label>车辆类型</label>
                            <select id="vehicleType" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                                <option value="电动车">电动车</option>
                                <option value="摩托车">摩托车</option>
                                <option value="自行车">自行车</option>
                            </select>
                        </div>
                        <div>
                            <label>车牌号</label>
                            <input type="text" id="licenseNumber" value="" style="width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                        </div>
                    </div>
                    <button class="btn btn-primary" onclick="updateRiderProfile()" style="margin-top: 15px;">保存修改</button>
                </div>
                
                <div class="profile-section">
                    <h3>工作状态</h3>
                    <div style="display: flex; gap: 15px; align-items: center;">
                        <div>
                            <label>当前状态</label>
                            <select id="workStatus" style="padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                                <option value="online">在线接单</option>
                                <option value="busy">配送中</option>
                                <option value="offline">离线</option>
                            </select>
                        </div>
                        <div>
                            <label>服务区域</label>
                            <input type="text" id="serviceArea" value="朝阳区" style="padding: 10px; border: 1px solid #ddd; border-radius: 8px;">
                        </div>
                        <button class="btn btn-success" onclick="updateWorkStatus()">更新状态</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="database.js"></script>
    <script>
        let currentUser = null;
        
        // 页面加载时初始化
        window.onload = function() {
            checkLoginStatus();
            loadDashboard();
            loadOrders();
            updateMapInfo();
            loadEarnings();
            loadProfile();
        };
        
        function checkLoginStatus() {
            const savedUser = localStorage.getItem('currentUser');
            if (savedUser) {
                currentUser = JSON.parse(savedUser);
                if (currentUser.type !== 'rider') {
                    alert('您没有权限访问骑手中心！');
                    window.location.href = 'home.html';
                    return;
                }
                document.getElementById('riderName').textContent = currentUser.name;
            } else {
                alert('请先登录！');
                window.location.href = 'login.html';
            }
        }
        
        function showTab(tabName) {
            // 隐藏所有标签页内容
            document.querySelectorAll('.tab-content').forEach(content => {
                content.classList.remove('active');
            });
            
            // 移除所有标签页的激活状态
            document.querySelectorAll('.tab').forEach(tab => {
                tab.classList.remove('active');
            });
            
            // 显示选中的标签页
            document.getElementById(tabName).classList.add('active');
            
            // 激活对应的标签按钮
            event.target.classList.add('active');
            
            // 根据标签页加载相应数据
            switch(tabName) {
                case 'dashboard':
                    loadDashboard();
                    break;
                case 'orders':
                    loadOrders();
                    break;
                case 'map':
                    updateMapInfo();
                    break;
                case 'earnings':
                    loadEarnings();
                    break;
            }
        }
        
        function loadDashboard() {
            if (!currentUser) return;
            
            const orders = db.getOrdersByRider(currentUser.id);
            const availableOrders = db.getAvailableOrders();
            
            // 计算今日数据
            const today = new Date().toDateString();
            const todayOrders = orders.filter(order => 
                new Date(order.orderTime).toDateString() === today
            );
            
            const todayEarnings = todayOrders.reduce((sum, order) => sum + (order.deliveryFee || 5), 0);
            const avgRating = currentUser.riderInfo?.rating || 4.9;
            const avgTime = 25; // 模拟数据
            
            document.getElementById('todayOrders').textContent = todayOrders.length;
            document.getElementById('todayEarnings').textContent = `¥${todayEarnings}`;
            document.getElementById('avgRating').textContent = avgRating;
            document.getElementById('avgTime').textContent = `${avgTime}分钟`;
        }
        
        function loadOrders() {
            if (!currentUser) return;
            
            const availableOrders = db.getAvailableOrders();
            const riderOrders = db.getOrdersByRider(currentUser.id);
            const allOrders = [...availableOrders, ...riderOrders];
            
            const ordersList = document.getElementById('ordersList');
            
            if (allOrders.length === 0) {
                ordersList.innerHTML = `
                    <div style="text-align: center; padding: 40px; color: #666;">
                        <p>暂无订单</p>
                    </div>
                `;
                return;
            }
            
            ordersList.innerHTML = allOrders.map(order => `
                <div class="order-card">
                    <div class="order-header">
                        <span class="order-id">订单号: #${order.id}</span>
                        <span class="order-status status-${order.riderStatus}">${getStatusText(order.riderStatus)}</span>
                    </div>
                    <div class="order-content">
                        <p><strong>商家:</strong> ${db.getMerchantById(order.merchantId)?.name || '未知商家'}</p>
                        <p><strong>客户:</strong> ${order.customerName}</p>
                        <p><strong>电话:</strong> ${order.customerPhone}</p>
                        <p><strong>地址:</strong> ${order.deliveryAddress}</p>
                        <p><strong>配送费:</strong> ¥${order.deliveryFee || 5}</p>
                        <p><strong>预计用时:</strong> ${order.estimatedTime || 25}分钟</p>
                        <p><strong>下单时间:</strong> ${order.orderTime}</p>
                    </div>
                    <div class="order-actions">
                        ${getOrderActions(order.riderStatus, order.id)}
                    </div>
                </div>
            `).join('');
        }
        
        function getStatusText(status) {
            const statusMap = {
                'available': '可接单',
                'accepted': '已接单',
                'delivering': '配送中',
                'completed': '已完成'
            };
            return statusMap[status] || status;
        }
        
        function getOrderActions(status, orderId) {
            switch(status) {
                case 'available':
                    return `<button class="btn btn-success" onclick="acceptOrder(${orderId})">接单</button>`;
                case 'accepted':
                    return `<button class="btn btn-primary" onclick="startDelivery(${orderId})">开始配送</button>`;
                case 'delivering':
                    return `<button class="btn btn-success" onclick="completeDelivery(${orderId})">完成配送</button>`;
                default:
                    return '';
            }
        }
        
        function acceptOrder(orderId) {
            const order = db.updateOrder(orderId, { 
                riderId: currentUser.id, 
                riderStatus: 'accepted',
                riderName: currentUser.name
            });
            if (order) {
                showMessage(`已接单 #${orderId}`, 'success');
                loadOrders();
                loadDashboard();
            }
        }
        
        function startDelivery(orderId) {
            const order = db.updateOrder(orderId, { riderStatus: 'delivering' });
            if (order) {
                showMessage(`开始配送订单 #${orderId}`, 'success');
                loadOrders();
            }
        }
        
        function completeDelivery(orderId) {
            const order = db.updateOrder(orderId, { 
                riderStatus: 'completed',
                status: 'completed'
            });
            if (order) {
                showMessage(`订单 #${orderId} 配送完成`, 'success');
                loadOrders();
                loadDashboard();
            }
        }
        
        function updateMapInfo() {
            const availableOrders = db.getAvailableOrders();
            const pendingOrders = availableOrders.length;
            const estimatedTime = pendingOrders * 25; // 假设每个订单25分钟
            
            document.getElementById('pendingOrders').textContent = pendingOrders;
            document.getElementById('estimatedTime').textContent = estimatedTime;
        }
        
        function refreshMap() {
            showMessage('地图已刷新', 'success');
            updateMapInfo();
        }
        
        function showRoute() {
            showMessage('显示最优配送路线', 'success');
        }
        
        function showMessage(text, type) {
            const messageDiv = document.getElementById('message');
            messageDiv.innerHTML = `<div class="message ${type}">${text}</div>`;
            setTimeout(() => {
                messageDiv.innerHTML = '';
            }, 3000);
        }
        
        function logout() {
            localStorage.removeItem('currentUser');
            window.location.href = 'home.html';
        }
        
        function goBack() {
            window.location.href = 'home.html';
        }
        
        // 收益分析功能
        function loadEarnings() {
            if (!currentUser) return;
            
            const orders = db.getOrdersByRider(currentUser.id);
            const today = new Date().toDateString();
            const todayOrders = orders.filter(order => 
                new Date(order.orderTime).toDateString() === today
            );
            
            const todayEarnings = todayOrders.reduce((sum, order) => sum + (order.deliveryFee || 5), 0);
            const avgPrice = todayOrders.length > 0 ? (todayEarnings / todayOrders.length).toFixed(1) : 0;
            
            // 计算本周收益
            const weekStart = new Date();
            weekStart.setDate(weekStart.getDate() - weekStart.getDay());
            const weekOrders = orders.filter(order => 
                new Date(order.orderTime) >= weekStart
            );
            const weeklyTotal = weekOrders.reduce((sum, order) => sum + (order.deliveryFee || 5), 0);
            
            document.getElementById('todayEarnings').textContent = `¥${todayEarnings}`;
            document.getElementById('todayOrders').textContent = `${todayOrders.length}单`;
            document.getElementById('avgPrice').textContent = `¥${avgPrice}`;
            document.getElementById('weeklyTotal').textContent = `¥${weeklyTotal}`;
            document.getElementById('weeklyGrowth').textContent = '+15.2%';
            document.getElementById('withdrawableAmount').textContent = `¥${weeklyTotal}`;
            
            loadRanking();
        }
        
        function loadRanking() {
            const rankingList = document.getElementById('rankingList');
            if (!rankingList) return;
            
            // 模拟排行榜数据
            const rankings = [
                { name: '张师傅', earnings: 1250, rank: 1 },
                { name: '李师傅', earnings: 1180, rank: 2 },
                { name: '王师傅', earnings: 1120, rank: 3 },
                { name: currentUser.name, earnings: 980, rank: 4 },
                { name: '赵师傅', earnings: 950, rank: 5 }
            ];
            
            rankingList.innerHTML = rankings.map(rider => `
                <div style="display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #eee;">
                    <div style="display: flex; align-items: center;">
                        <span style="background: ${rider.rank <= 3 ? '#ff6b6b' : '#6c757d'}; color: white; border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 12px; margin-right: 10px;">${rider.rank}</span>
                        <span style="${rider.name === currentUser.name ? 'color: #ff6b6b; font-weight: bold;' : ''}">${rider.name}</span>
                    </div>
                    <span style="color: #28a745; font-weight: bold;">¥${rider.earnings}</span>
                </div>
            `).join('');
        }
        
        function withdraw() {
            const amount = document.getElementById('withdrawAmount').value;
            if (!amount || amount <= 0) {
                showMessage('请输入有效的提现金额！', 'error');
                return;
            }
            
            const withdrawable = parseInt(document.getElementById('withdrawableAmount').textContent.replace('¥', ''));
            if (parseInt(amount) > withdrawable) {
                showMessage('提现金额不能超过可提现金额！', 'error');
                return;
            }
            
            if (confirm(`确定要提现 ¥${amount} 吗？`)) {
                showMessage('提现申请已提交，预计1-3个工作日到账！', 'success');
                document.getElementById('withdrawAmount').value = '';
            }
        }
        
        // 个人资料功能
        function loadProfile() {
            if (currentUser) {
                document.getElementById('riderName').value = currentUser.name || '';
                document.getElementById('riderPhone').value = currentUser.phone || '';
                document.getElementById('vehicleType').value = currentUser.riderInfo?.vehicle || '电动车';
                document.getElementById('licenseNumber').value = currentUser.riderInfo?.license || '';
                document.getElementById('serviceArea').value = currentUser.riderInfo?.area || '朝阳区';
            }
        }
        
        function updateRiderProfile() {
            const name = document.getElementById('riderName').value;
            const phone = document.getElementById('riderPhone').value;
            const vehicle = document.getElementById('vehicleType').value;
            const license = document.getElementById('licenseNumber').value;
            const area = document.getElementById('serviceArea').value;
            
            if (currentUser) {
                db.updateUser(currentUser.id, {
                    name: name,
                    phone: phone,
                    riderInfo: {
                        ...currentUser.riderInfo,
                        vehicle: vehicle,
                        license: license,
                        area: area
                    }
                });
                
                // 更新当前用户信息
                currentUser.name = name;
                currentUser.phone = phone;
                currentUser.riderInfo = {
                    ...currentUser.riderInfo,
                    vehicle: vehicle,
                    license: license,
                    area: area
                };
                localStorage.setItem('currentUser', JSON.stringify(currentUser));
                
                showMessage('个人信息更新成功！', 'success');
            }
        }
        
        function updateWorkStatus() {
            const status = document.getElementById('workStatus').value;
            const area = document.getElementById('serviceArea').value;
            
            if (currentUser) {
                db.updateUser(currentUser.id, {
                    riderInfo: {
                        ...currentUser.riderInfo,
                        status: status,
                        area: area
                    }
                });
                
                currentUser.riderInfo = {
                    ...currentUser.riderInfo,
                    status: status,
                    area: area
                };
                localStorage.setItem('currentUser', JSON.stringify(currentUser));
                
                const statusText = {
                    'online': '在线接单',
                    'busy': '配送中',
                    'offline': '离线'
                };
                
                showMessage(`工作状态已更新为：${statusText[status]}`, 'success');
            }
        }
    </script>
</body>
</html>
